﻿using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Net;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
using System.Web.Services;
using System.Web.Services.Description;
using System.Web.Services.Protocols;
using System.Xml.Serialization;

namespace SCSInternetBanking.LibertyReserve
{
    public class SoapApiAgent : IApiAgent, IDisposable
    {
        private readonly SCSInternetBanking.LibertyReserve.Soap.ApiServiceProxy m_proxy;

        public SoapApiAgent(ApiCredentials credentials)
        {
            m_proxy = new SCSInternetBanking.LibertyReserve.Soap.ApiServiceProxy();
            Credentials = credentials;
            RequireValidSslCertificate = true;

            ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(SertificateValidation);
        }

        public int Timeout
        {
            get { return m_proxy.Timeout; }

            set { m_proxy.Timeout = value; }
        }

        public string Host
        {
            get
            {
                UriBuilder fullUrl = new UriBuilder(m_proxy.Url);
                return new UriBuilder(fullUrl.Scheme, fullUrl.Host, fullUrl.Port).Uri.AbsoluteUri;
            }

            set
            {
                UriBuilder current = new UriBuilder(m_proxy.Url);
                UriBuilder newValue = new UriBuilder(value);
                current.Scheme = newValue.Scheme;
                current.Host = newValue.Host;
                current.Port = newValue.Port;
                m_proxy.Url = current.Uri.AbsoluteUri;
            }
        }

        public bool RequireValidSslCertificate { get; set; }

        public ApiCredentials Credentials { get; set; }

        public Balance Balance()
        {
            SetupCredentials();
            try
            {
                Soap.Balance balance = m_proxy.Balance();
                return balance == null ? null : new Balance()
                {
                    Usd = balance.Usd,
                    Euro = balance.Euro,
                    Gold = balance.Gold
                };
            }
            catch (SoapException sex)
            {
                throw new ApiException(sex.Message, sex);
            }
            catch (WebException wex)
            {
                throw new ApiException(wex.Message, wex);
            }
        }

        public HistoryResult History(HistorySpecification specification, int pageIndex, int pageSize)
        {
            SetupCredentials();
            Soap.HistorySpecification request = new Soap.HistorySpecification()
            {
                From = specification.From,
                Till = specification.Till,
                Currency = (Soap.SearchCurrency)specification.Currency,
                Direction = (Soap.SearchDirection)specification.Direction,
                RelatedAccount = specification.RelatedAccount,
                Reference = specification.Reference,
                Source = (Soap.SearchSource)specification.Source,
                Private = (Soap.SearchPrivate)specification.Private,
                AmountFrom = specification.AmountFrom,
                AmountTo = specification.AmountTo
            };

            try
            {
                List<HistoryItem> resultList = new List<HistoryItem>();
                Soap.HistoryResult response = m_proxy.History(request, pageIndex, pageSize);
                foreach (Soap.Transaction transaction in response.Transactions)
                {
                    resultList.Add(CreateHistoryItem(transaction));
                }

                return new HistoryResult()
                {
                    Items = resultList.ToArray(),
                    HasMore = response.HasMore
                };
            }
            catch (SoapException sex)
            {
                throw new ApiException(sex.Message, sex);
            }
            catch (WebException wex)
            {
                throw new ApiException(wex.Message, wex);
            }
        }

        public HistoryItem FindTransaction(long batchNumber)
        {
            SetupCredentials();
            try
            {
                Soap.Transaction response = m_proxy.FindTransaction(batchNumber);
                return response == null ? null : CreateHistoryItem(response);
            }
            catch (SoapException sex)
            {
                throw new ApiException(sex.Message, sex);
            }
            catch (WebException wex)
            {
                throw new ApiException(wex.Message, wex);
            }
        }

        public HistoryItem Transfer(Transfer transfer)
        {
            SetupCredentials();
            Soap.Transfer request = new Soap.Transfer()
            {
                Payee = transfer.Payee,
                Amount = transfer.Amount,
                Currency = (Soap.Currency)transfer.Currency,
                Memo = transfer.Memo,
                Reference = transfer.Reference,
                Private = transfer.Private,
                Purpose = (Soap.PaymentPurpose)transfer.Purpose
            };

            try
            {
                Soap.Transaction response = m_proxy.Transfer(request);
                return response == null ? null : CreateHistoryItem(response);
            }
            catch (SoapException sex)
            {
                throw new ApiException(sex.Message, sex);
            }
            catch (WebException wex)
            {
                throw new ApiException(wex.Message, wex);
            }
        }

        public string AccountName(string accountNumber)
        {
            SetupCredentials();

            try
            {
                return m_proxy.AccountName(accountNumber);
            }
            catch (SoapException sex)
            {
                throw new ApiException(sex.Message, sex);
            }
            catch (WebException wex)
            {
                throw new ApiException(wex.Message, wex);
            }
        }

        public bool SertificateValidation(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
        {
            HttpWebRequest request = sender as HttpWebRequest;
            return sslPolicyErrors == SslPolicyErrors.None || (!RequireValidSslCertificate && request != null && request.RequestUri.Host == new UriBuilder(m_proxy.Url).Host);
        }

        public void Dispose()
        {
            ServicePointManager.ServerCertificateValidationCallback -= new RemoteCertificateValidationCallback(SertificateValidation);
        }

        private void SetupCredentials()
        {
            m_proxy.AuthenticationValue = new Soap.Authentication()
            {
                AccountNumber = Credentials.AccountNumber,
                ApiName = Credentials.ApiName,
                Token = Credentials.CreateSecurityToken()
            };
        }

        private static HistoryItem CreateHistoryItem(Soap.Transaction transaction)
        {
            return new HistoryItem()
            {
                Amount = transaction.Amount,
                Balance = transaction.Balance,
                Batch = transaction.Batch,
                Currency = (Currency)transaction.Currency,
                Date = transaction.Date,
                Fee = transaction.Fee,
                Memo = transaction.Memo,
                Payee = transaction.Payee,
                PayeeName = transaction.PayeeName,
                Payer = transaction.Payer,
                PayerName = transaction.PayerName,
                Private = transaction.Private,
                Reference = transaction.Reference,
                Source = (Source)transaction.Source
            };
        }
    }
}

namespace SCSInternetBanking.LibertyReserve.Soap
{
    [GeneratedCode("wsdl", "2.0.50727.3038")]
    [DebuggerStepThrough()]
    [DesignerCategory("code")]
    [WebServiceBinding(Name = "ApiServiceSoap", Namespace = "https://api2.SCSInternetBanking.LibertyReserve.com/soap/")]
    public partial class ApiServiceProxy : SoapHttpClientProtocol
    {
        private Authentication authenticationValueField;

        private System.Threading.SendOrPostCallback AccountNameOperationCompleted;

        private System.Threading.SendOrPostCallback BalanceOperationCompleted;

        private System.Threading.SendOrPostCallback FindTransactionOperationCompleted;

        private System.Threading.SendOrPostCallback HistoryOperationCompleted;

        private System.Threading.SendOrPostCallback TransferOperationCompleted;

        private System.Threading.SendOrPostCallback BulkTransferOperationCompleted;

        public ApiServiceProxy()
        {
            this.Url = "https://api2.SCSInternetBanking.LibertyReserve.com/services/apiservice.asmx";
        }

        public Authentication AuthenticationValue
        {
            get
            {
                return this.authenticationValueField;
            }
            set
            {
                this.authenticationValueField = value;
            }
        }

        public event AccountNameCompletedEventHandler AccountNameCompleted;

        public event BalanceCompletedEventHandler BalanceCompleted;

        public event FindTransactionCompletedEventHandler FindTransactionCompleted;

        public event HistoryCompletedEventHandler HistoryCompleted;

        public event TransferCompletedEventHandler TransferCompleted;

        public event BulkTransferCompletedEventHandler BulkTransferCompleted;

        [SoapHeader("AuthenticationValue")]
        [SoapRpcMethod("https://api2.SCSInternetBanking.LibertyReserve.com/soap/AccountName", RequestNamespace = "https://api2.SCSInternetBanking.LibertyReserve.com/soap/", ResponseNamespace = "https://api2.SCSInternetBanking.LibertyReserve.com/soap/", Use = SoapBindingUse.Literal)]
        public string AccountName(string accountToRetrieve)
        {
            object[] results = this.Invoke("AccountName", new object[] {
                    accountToRetrieve});
            return ((string)(results[0]));
        }

        public IAsyncResult BeginAccountName(string accountToRetrieve, System.AsyncCallback callback, object asyncState)
        {
            return this.BeginInvoke("AccountName", new object[] {
                    accountToRetrieve}, callback, asyncState);
        }

        public string EndAccountName(IAsyncResult asyncResult)
        {
            object[] results = this.EndInvoke(asyncResult);
            return ((string)(results[0]));
        }

        public void AccountNameAsync(string accountToRetrieve)
        {
            this.AccountNameAsync(accountToRetrieve, null);
        }

        public void AccountNameAsync(string accountToRetrieve, object userState)
        {
            if ((this.AccountNameOperationCompleted == null))
            {
                this.AccountNameOperationCompleted = new System.Threading.SendOrPostCallback(this.OnAccountNameOperationCompleted);
            }
            this.InvokeAsync("AccountName", new object[] {
                    accountToRetrieve}, this.AccountNameOperationCompleted, userState);
        }

        private void OnAccountNameOperationCompleted(object arg)
        {
            if ((this.AccountNameCompleted != null))
            {
                InvokeCompletedEventArgs invokeArgs = ((InvokeCompletedEventArgs)(arg));
                this.AccountNameCompleted(this, new AccountNameCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState));
            }
        }

        [SoapHeader("AuthenticationValue")]
        [SoapRpcMethod("https://api2.SCSInternetBanking.LibertyReserve.com/soap/Balance", RequestNamespace = "https://api2.SCSInternetBanking.LibertyReserve.com/soap/", ResponseNamespace = "https://api2.SCSInternetBanking.LibertyReserve.com/soap/", Use = SoapBindingUse.Literal)]
        public Balance Balance()
        {
            object[] results = this.Invoke("Balance", new object[0]);
            return ((Balance)(results[0]));
        }

        public IAsyncResult BeginBalance(System.AsyncCallback callback, object asyncState)
        {
            return this.BeginInvoke("Balance", new object[0], callback, asyncState);
        }

        public Balance EndBalance(IAsyncResult asyncResult)
        {
            object[] results = this.EndInvoke(asyncResult);
            return ((Balance)(results[0]));
        }

        public void BalanceAsync()
        {
            this.BalanceAsync(null);
        }

        public void BalanceAsync(object userState)
        {
            if ((this.BalanceOperationCompleted == null))
            {
                this.BalanceOperationCompleted = new System.Threading.SendOrPostCallback(this.OnBalanceOperationCompleted);
            }
            this.InvokeAsync("Balance", new object[0], this.BalanceOperationCompleted, userState);
        }

        private void OnBalanceOperationCompleted(object arg)
        {
            if ((this.BalanceCompleted != null))
            {
                InvokeCompletedEventArgs invokeArgs = ((InvokeCompletedEventArgs)(arg));
                this.BalanceCompleted(this, new BalanceCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState));
            }
        }

        [SoapHeader("AuthenticationValue")]
        [SoapRpcMethod("https://api2.SCSInternetBanking.LibertyReserve.com/soap/FindTransaction", RequestNamespace = "https://api2.SCSInternetBanking.LibertyReserve.com/soap/", ResponseNamespace = "https://api2.SCSInternetBanking.LibertyReserve.com/soap/", Use = SoapBindingUse.Literal)]
        public Transaction FindTransaction(long batch)
        {
            object[] results = this.Invoke("FindTransaction", new object[] {
                    batch});
            return ((Transaction)(results[0]));
        }

        public IAsyncResult BeginFindTransaction(long batch, System.AsyncCallback callback, object asyncState)
        {
            return this.BeginInvoke("FindTransaction", new object[] {
                    batch}, callback, asyncState);
        }

        public Transaction EndFindTransaction(IAsyncResult asyncResult)
        {
            object[] results = this.EndInvoke(asyncResult);
            return ((Transaction)(results[0]));
        }

        public void FindTransactionAsync(long batch)
        {
            this.FindTransactionAsync(batch, null);
        }

        public void FindTransactionAsync(long batch, object userState)
        {
            if ((this.FindTransactionOperationCompleted == null))
            {
                this.FindTransactionOperationCompleted = new System.Threading.SendOrPostCallback(this.OnFindTransactionOperationCompleted);
            }
            this.InvokeAsync("FindTransaction", new object[] {
                    batch}, this.FindTransactionOperationCompleted, userState);
        }

        private void OnFindTransactionOperationCompleted(object arg)
        {
            if ((this.FindTransactionCompleted != null))
            {
                InvokeCompletedEventArgs invokeArgs = ((InvokeCompletedEventArgs)(arg));
                this.FindTransactionCompleted(this, new FindTransactionCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState));
            }
        }

        [SoapHeader("AuthenticationValue")]
        [SoapRpcMethod("https://api2.SCSInternetBanking.LibertyReserve.com/soap/History", RequestNamespace = "https://api2.SCSInternetBanking.LibertyReserve.com/soap/", ResponseNamespace = "https://api2.SCSInternetBanking.LibertyReserve.com/soap/", Use = SoapBindingUse.Literal)]
        public HistoryResult History(HistorySpecification specification, int pageIndex, int pageSize)
        {
            object[] results = this.Invoke("History", new object[] {
                    specification,
                    pageIndex,
                    pageSize});
            return ((HistoryResult)(results[0]));
        }

        public IAsyncResult BeginHistory(HistorySpecification specification, int pageIndex, int pageSize, System.AsyncCallback callback, object asyncState)
        {
            return this.BeginInvoke("History", new object[] {
                    specification,
                    pageIndex,
                    pageSize}, callback, asyncState);
        }

        public HistoryResult EndHistory(IAsyncResult asyncResult)
        {
            object[] results = this.EndInvoke(asyncResult);
            return ((HistoryResult)(results[0]));
        }

        public void HistoryAsync(HistorySpecification specification, int pageIndex, int pageSize)
        {
            this.HistoryAsync(specification, pageIndex, pageSize, null);
        }

        public void HistoryAsync(HistorySpecification specification, int pageIndex, int pageSize, object userState)
        {
            if ((this.HistoryOperationCompleted == null))
            {
                this.HistoryOperationCompleted = new System.Threading.SendOrPostCallback(this.OnHistoryOperationCompleted);
            }
            this.InvokeAsync("History", new object[] {
                    specification,
                    pageIndex,
                    pageSize}, this.HistoryOperationCompleted, userState);
        }

        private void OnHistoryOperationCompleted(object arg)
        {
            if ((this.HistoryCompleted != null))
            {
                InvokeCompletedEventArgs invokeArgs = ((InvokeCompletedEventArgs)(arg));
                this.HistoryCompleted(this, new HistoryCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState));
            }
        }

        [SoapHeader("AuthenticationValue")]
        [SoapRpcMethod("https://api2.SCSInternetBanking.LibertyReserve.com/soap/Transfer", RequestNamespace = "https://api2.SCSInternetBanking.LibertyReserve.com/soap/", ResponseNamespace = "https://api2.SCSInternetBanking.LibertyReserve.com/soap/", Use = SoapBindingUse.Literal)]
        public Transaction Transfer(Transfer transferInfo)
        {
            object[] results = this.Invoke("Transfer", new object[] {
                    transferInfo});
            return ((Transaction)(results[0]));
        }

        public IAsyncResult BeginTransfer(Transfer transferInfo, System.AsyncCallback callback, object asyncState)
        {
            return this.BeginInvoke("Transfer", new object[] {
                    transferInfo}, callback, asyncState);
        }

        public Transaction EndTransfer(IAsyncResult asyncResult)
        {
            object[] results = this.EndInvoke(asyncResult);
            return ((Transaction)(results[0]));
        }

        public void TransferAsync(Transfer transfer)
        {
            this.TransferAsync(transfer, null);
        }

        public void TransferAsync(Transfer transfer, object userState)
        {
            if ((this.TransferOperationCompleted == null))
            {
                this.TransferOperationCompleted = new System.Threading.SendOrPostCallback(this.OnTransferOperationCompleted);
            }
            this.InvokeAsync("Transfer", new object[] {
                    transfer}, this.TransferOperationCompleted, userState);
        }

        private void OnTransferOperationCompleted(object arg)
        {
            if ((this.TransferCompleted != null))
            {
                InvokeCompletedEventArgs invokeArgs = ((InvokeCompletedEventArgs)(arg));
                this.TransferCompleted(this, new TransferCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState));
            }
        }

        [SoapHeader("AuthenticationValue")]
        [SoapRpcMethod("https://api2.SCSInternetBanking.LibertyReserve.com/soap/BulkTransfer", RequestNamespace = "https://api2.SCSInternetBanking.LibertyReserve.com/soap/", ResponseNamespace = "https://api2.SCSInternetBanking.LibertyReserve.com/soap/", Use = SoapBindingUse.Literal)]
        [return: XmlArray()]
        [return: XmlArrayItem(Namespace = "https://api2.SCSInternetBanking.LibertyReserve.com/soap/")]
        public Transaction[] BulkTransfer([XmlArrayItem(Namespace = "https://api2.SCSInternetBanking.LibertyReserve.com/soap/")] Transfer[] transfers)
        {
            object[] results = this.Invoke("BulkTransfer", new object[] {
                    transfers});
            return ((Transaction[])(results[0]));
        }

        public IAsyncResult BeginBulkTransfer(Transfer[] transfers, System.AsyncCallback callback, object asyncState)
        {
            return this.BeginInvoke("BulkTransfer", new object[] {
                    transfers}, callback, asyncState);
        }

        public Transaction[] EndBulkTransfer(IAsyncResult asyncResult)
        {
            object[] results = this.EndInvoke(asyncResult);
            return ((Transaction[])(results[0]));
        }

        public void BulkTransferAsync(Transfer[] transfers)
        {
            this.BulkTransferAsync(transfers, null);
        }

        public void BulkTransferAsync(Transfer[] transfers, object userState)
        {
            if ((this.BulkTransferOperationCompleted == null))
            {
                this.BulkTransferOperationCompleted = new System.Threading.SendOrPostCallback(this.OnBulkTransferOperationCompleted);
            }
            this.InvokeAsync("BulkTransfer", new object[] {
                    transfers}, this.BulkTransferOperationCompleted, userState);
        }

        private void OnBulkTransferOperationCompleted(object arg)
        {
            if ((this.BulkTransferCompleted != null))
            {
                InvokeCompletedEventArgs invokeArgs = ((InvokeCompletedEventArgs)(arg));
                this.BulkTransferCompleted(this, new BulkTransferCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState));
            }
        }

        public new void CancelAsync(object userState)
        {
            base.CancelAsync(userState);
        }
    }

    [GeneratedCode("wsdl", "2.0.50727.3038")]
    [Serializable()]
    [DebuggerStepThrough()]
    [DesignerCategory("code")]
    [XmlType(Namespace = "https://api2.SCSInternetBanking.LibertyReserve.com/soap/")]
    [XmlRoot(Namespace = "https://api2.SCSInternetBanking.LibertyReserve.com/soap/", IsNullable = false)]
    public partial class Authentication : SoapHeader
    {
        private string accountNumberField;

        private string apiNameField;

        private string tokenField;

        private System.Xml.XmlAttribute[] anyAttrField;

        public string AccountNumber
        {
            get
            {
                return this.accountNumberField;
            }
            set
            {
                this.accountNumberField = value;
            }
        }

        public string ApiName
        {
            get
            {
                return this.apiNameField;
            }
            set
            {
                this.apiNameField = value;
            }
        }

        public string Token
        {
            get
            {
                return this.tokenField;
            }
            set
            {
                this.tokenField = value;
            }
        }

        [XmlAnyAttribute()]
        public System.Xml.XmlAttribute[] AnyAttr
        {
            get
            {
                return this.anyAttrField;
            }
            set
            {
                this.anyAttrField = value;
            }
        }
    }

    [GeneratedCode("wsdl", "2.0.50727.3038")]
    [Serializable()]
    [DebuggerStepThrough()]
    [DesignerCategory("code")]
    [XmlType(Namespace = "https://api2.SCSInternetBanking.LibertyReserve.com/soap/")]
    public partial class Transfer
    {
        private string payeeField;

        private Currency currencyField;

        private decimal amountField;

        private string memoField;

        private string referenceField;

        private bool privateField;

        private PaymentPurpose purposeField;

        public string Payee
        {
            get
            {
                return this.payeeField;
            }
            set
            {
                this.payeeField = value;
            }
        }

        public Currency Currency
        {
            get
            {
                return this.currencyField;
            }
            set
            {
                this.currencyField = value;
            }
        }

        public decimal Amount
        {
            get
            {
                return this.amountField;
            }
            set
            {
                this.amountField = value;
            }
        }

        public string Memo
        {
            get
            {
                return this.memoField;
            }
            set
            {
                this.memoField = value;
            }
        }

        public string Reference
        {
            get
            {
                return this.referenceField;
            }
            set
            {
                this.referenceField = value;
            }
        }

        public bool Private
        {
            get
            {
                return this.privateField;
            }
            set
            {
                this.privateField = value;
            }
        }

        public PaymentPurpose Purpose
        {
            get
            {
                return this.purposeField;
            }
            set
            {
                this.purposeField = value;
            }
        }
    }

    [GeneratedCode("wsdl", "2.0.50727.3038")]
    [Serializable()]
    [XmlType(Namespace = "https://api2.SCSInternetBanking.LibertyReserve.com/soap/")]
    public enum Currency
    {
        None,

        Usd,

        Euro,

        Gold,
    }

    [GeneratedCode("wsdl", "2.0.50727.3038")]
    [Serializable()]
    [XmlType(Namespace = "https://api2.SCSInternetBanking.LibertyReserve.com/soap/")]
    public enum PaymentPurpose
    {
        None,

        Service,

        Salary,
    }

    [GeneratedCode("wsdl", "2.0.50727.3038")]
    [Serializable()]
    [DebuggerStepThrough()]
    [DesignerCategory("code")]
    [XmlType(Namespace = "https://api2.SCSInternetBanking.LibertyReserve.com/soap/")]
    public partial class HistoryResult
    {
        private Transaction[] transactionsField;

        private bool hasMoreField;

        public Transaction[] Transactions
        {
            get
            {
                return this.transactionsField;
            }
            set
            {
                this.transactionsField = value;
            }
        }

        public bool HasMore
        {
            get
            {
                return this.hasMoreField;
            }
            set
            {
                this.hasMoreField = value;
            }
        }
    }

    [GeneratedCode("wsdl", "2.0.50727.3038")]
    [Serializable()]
    [DebuggerStepThrough()]
    [DesignerCategory("code")]
    [XmlType(Namespace = "https://api2.SCSInternetBanking.LibertyReserve.com/soap/")]
    public partial class Transaction
    {
        private long batchField;

        private DateTime dateField;

        private Currency currencyField;

        private decimal amountField;

        private decimal feeField;

        private decimal balanceField;

        private string memoField;

        private string referenceField;

        private Source sourceField;

        private bool privateField;

        private string payerField;

        private string payerNameField;

        private string payeeField;

        private string payeeNameField;

        public long Batch
        {
            get
            {
                return this.batchField;
            }
            set
            {
                this.batchField = value;
            }
        }

        public DateTime Date
        {
            get
            {
                return this.dateField;
            }
            set
            {
                this.dateField = value;
            }
        }

        public Currency Currency
        {
            get
            {
                return this.currencyField;
            }
            set
            {
                this.currencyField = value;
            }
        }

        public decimal Amount
        {
            get
            {
                return this.amountField;
            }
            set
            {
                this.amountField = value;
            }
        }

        public decimal Fee
        {
            get
            {
                return this.feeField;
            }
            set
            {
                this.feeField = value;
            }
        }

        public decimal Balance
        {
            get
            {
                return this.balanceField;
            }
            set
            {
                this.balanceField = value;
            }
        }

        public string Memo
        {
            get
            {
                return this.memoField;
            }
            set
            {
                this.memoField = value;
            }
        }

        public string Reference
        {
            get
            {
                return this.referenceField;
            }
            set
            {
                this.referenceField = value;
            }
        }

        public Source Source
        {
            get
            {
                return this.sourceField;
            }
            set
            {
                this.sourceField = value;
            }
        }

        public bool Private
        {
            get
            {
                return this.privateField;
            }
            set
            {
                this.privateField = value;
            }
        }

        public string Payer
        {
            get
            {
                return this.payerField;
            }
            set
            {
                this.payerField = value;
            }
        }

        public string PayerName
        {
            get
            {
                return this.payerNameField;
            }
            set
            {
                this.payerNameField = value;
            }
        }

        public string Payee
        {
            get
            {
                return this.payeeField;
            }
            set
            {
                this.payeeField = value;
            }
        }

        public string PayeeName
        {
            get
            {
                return this.payeeNameField;
            }
            set
            {
                this.payeeNameField = value;
            }
        }
    }

    [GeneratedCode("wsdl", "2.0.50727.3038")]
    [Serializable()]
    [XmlType(Namespace = "https://api2.SCSInternetBanking.LibertyReserve.com/soap/")]
    public enum Source
    {
        None,

        Site,

        Wallet,

        Api,

        Sci,
    }

    [GeneratedCode("wsdl", "2.0.50727.3038")]
    [Serializable()]
    [DebuggerStepThrough()]
    [DesignerCategory("code")]
    [XmlType(Namespace = "https://api2.SCSInternetBanking.LibertyReserve.com/soap/")]
    public partial class HistorySpecification
    {
        private DateTime fromField;

        private DateTime tillField;

        private decimal amountFromField;

        private decimal amountToField;

        private string relatedAccountField;

        private SearchCurrency currencyField;

        private SearchDirection directionField;

        private SearchSource sourceField;

        private SearchPrivate privateField;

        private string referenceField;

        public DateTime From
        {
            get
            {
                return this.fromField;
            }
            set
            {
                this.fromField = value;
            }
        }

        public DateTime Till
        {
            get
            {
                return this.tillField;
            }
            set
            {
                this.tillField = value;
            }
        }

        public decimal AmountFrom
        {
            get
            {
                return this.amountFromField;
            }
            set
            {
                this.amountFromField = value;
            }
        }

        public decimal AmountTo
        {
            get
            {
                return this.amountToField;
            }
            set
            {
                this.amountToField = value;
            }
        }

        public string RelatedAccount
        {
            get
            {
                return this.relatedAccountField;
            }
            set
            {
                this.relatedAccountField = value;
            }
        }

        public SearchCurrency Currency
        {
            get
            {
                return this.currencyField;
            }
            set
            {
                this.currencyField = value;
            }
        }

        public SearchDirection Direction
        {
            get
            {
                return this.directionField;
            }
            set
            {
                this.directionField = value;
            }
        }

        public SearchSource Source
        {
            get
            {
                return this.sourceField;
            }
            set
            {
                this.sourceField = value;
            }
        }

        public SearchPrivate Private
        {
            get
            {
                return this.privateField;
            }
            set
            {
                this.privateField = value;
            }
        }

        public string Reference
        {
            get
            {
                return this.referenceField;
            }
            set
            {
                this.referenceField = value;
            }
        }
    }

    [GeneratedCode("wsdl", "2.0.50727.3038")]
    [Serializable()]
    [XmlType(Namespace = "https://api2.SCSInternetBanking.LibertyReserve.com/soap/")]
    public enum SearchCurrency
    {
        Any,

        Usd,

        Euro,

        Gold,
    }

    [GeneratedCode("wsdl", "2.0.50727.3038")]
    [Serializable()]
    [XmlType(Namespace = "https://api2.SCSInternetBanking.LibertyReserve.com/soap/")]
    public enum SearchDirection
    {
        Any,

        Incoming,

        Outgoing,
    }

    [GeneratedCode("wsdl", "2.0.50727.3038")]
    [Serializable()]
    [XmlType(Namespace = "https://api2.SCSInternetBanking.LibertyReserve.com/soap/")]
    public enum SearchSource
    {
        Any,

        Site,

        Wallet,

        Api,

        Sci,
    }

    [GeneratedCode("wsdl", "2.0.50727.3038")]
    [Serializable()]
    [XmlType(Namespace = "https://api2.SCSInternetBanking.LibertyReserve.com/soap/")]
    public enum SearchPrivate
    {
        Any,

        Yes,

        No,
    }

    [GeneratedCode("wsdl", "2.0.50727.3038")]
    [Serializable()]
    [DebuggerStepThrough()]
    [DesignerCategory("code")]
    [XmlType(Namespace = "https://api2.SCSInternetBanking.LibertyReserve.com/soap/")]
    public partial class Balance
    {
        private decimal usdField;

        private decimal euroField;

        private decimal goldField;

        public decimal Usd
        {
            get
            {
                return this.usdField;
            }
            set
            {
                this.usdField = value;
            }
        }

        public decimal Euro
        {
            get
            {
                return this.euroField;
            }
            set
            {
                this.euroField = value;
            }
        }

        public decimal Gold
        {
            get
            {
                return this.goldField;
            }
            set
            {
                this.goldField = value;
            }
        }
    }

    [GeneratedCode("wsdl", "2.0.50727.3038")]
    public delegate void AccountNameCompletedEventHandler(object sender, AccountNameCompletedEventArgs e);

    [GeneratedCode("wsdl", "2.0.50727.3038")]
    [DebuggerStepThrough()]
    [DesignerCategory("code")]
    public partial class AccountNameCompletedEventArgs : AsyncCompletedEventArgs
    {
        private object[] results;

        internal AccountNameCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) :
            base(exception, cancelled, userState)
        {
            this.results = results;
        }

        public string Result
        {
            get
            {
                this.RaiseExceptionIfNecessary();
                return ((string)(this.results[0]));
            }
        }
    }

    [GeneratedCode("wsdl", "2.0.50727.3038")]
    public delegate void BalanceCompletedEventHandler(object sender, BalanceCompletedEventArgs e);

    [GeneratedCode("wsdl", "2.0.50727.3038")]
    [DebuggerStepThrough()]
    [DesignerCategory("code")]
    public partial class BalanceCompletedEventArgs : AsyncCompletedEventArgs
    {
        private object[] results;

        internal BalanceCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) :
            base(exception, cancelled, userState)
        {
            this.results = results;
        }

        public Balance Result
        {
            get
            {
                this.RaiseExceptionIfNecessary();
                return ((Balance)(this.results[0]));
            }
        }
    }

    [GeneratedCode("wsdl", "2.0.50727.3038")]
    public delegate void FindTransactionCompletedEventHandler(object sender, FindTransactionCompletedEventArgs e);

    [GeneratedCode("wsdl", "2.0.50727.3038")]
    [DebuggerStepThrough()]
    [DesignerCategory("code")]
    public partial class FindTransactionCompletedEventArgs : AsyncCompletedEventArgs
    {
        private object[] results;

        internal FindTransactionCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) :
            base(exception, cancelled, userState)
        {
            this.results = results;
        }

        public Transaction Result
        {
            get
            {
                this.RaiseExceptionIfNecessary();
                return ((Transaction)(this.results[0]));
            }
        }
    }

    [GeneratedCode("wsdl", "2.0.50727.3038")]
    public delegate void HistoryCompletedEventHandler(object sender, HistoryCompletedEventArgs e);

    [GeneratedCode("wsdl", "2.0.50727.3038")]
    [DebuggerStepThrough()]
    [DesignerCategory("code")]
    public partial class HistoryCompletedEventArgs : AsyncCompletedEventArgs
    {
        private object[] results;

        internal HistoryCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) :
            base(exception, cancelled, userState)
        {
            this.results = results;
        }

        public HistoryResult Result
        {
            get
            {
                this.RaiseExceptionIfNecessary();
                return ((HistoryResult)(this.results[0]));
            }
        }
    }

    [GeneratedCode("wsdl", "2.0.50727.3038")]
    public delegate void TransferCompletedEventHandler(object sender, TransferCompletedEventArgs e);

    [GeneratedCode("wsdl", "2.0.50727.3038")]
    [DebuggerStepThrough()]
    [DesignerCategory("code")]
    public partial class TransferCompletedEventArgs : AsyncCompletedEventArgs
    {
        private object[] results;

        internal TransferCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) :
            base(exception, cancelled, userState)
        {
            this.results = results;
        }

        public Transaction Result
        {
            get
            {
                this.RaiseExceptionIfNecessary();
                return ((Transaction)(this.results[0]));
            }
        }
    }

    [GeneratedCode("wsdl", "2.0.50727.3038")]
    public delegate void BulkTransferCompletedEventHandler(object sender, BulkTransferCompletedEventArgs e);

    [GeneratedCode("wsdl", "2.0.50727.3038")]
    [DebuggerStepThrough()]
    [DesignerCategory("code")]
    public partial class BulkTransferCompletedEventArgs : AsyncCompletedEventArgs
    {
        private object[] results;

        internal BulkTransferCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) :
            base(exception, cancelled, userState)
        {
            this.results = results;
        }

        public Transaction[] Result
        {
            get
            {
                this.RaiseExceptionIfNecessary();
                return ((Transaction[])(this.results[0]));
            }
        }
    }
}